import { httpGet, handleResult } from "./http";
import moment from "moment";

//列表
export async function pageList(params) {
  const url = "/gm_student/list";
  // return await httpGet(url, params).then(res => res.data.data);
  return await httpGet(url, params).then(res => {
    res.data.data.list.map(p => {
      if (p.birthday) p.birthday = moment(new Date(p.birthday)).format("YYYY-MM-DD");
      p.createAt = null;
      p.updateAt = null;
    });
    return res.data.data;
  });
}
//新增
export async function add(data) {
  // const url = "/gm_student/insert?classNo=1&teacherId=1";
  // return await httpGet(url);
  // params.teacherId = 1;
  const url = "/gm_student/insert";
  if (data.birthday) data.birthday = moment(new Date(data.birthday)).format("YYYY-MM-DD");
  return await httpGet(url, data).then(handleResult);
}
//批量生成
export async function generate(params) {
  const url = "/gm_student/generate";
  return await httpGet(url, params).then(handleResult);
}
//更新
export async function update(data) {
  const url = "/gm_student/update";
  return await httpGet(url, data).then(handleResult);
}
//绑定班主任
export async function bindHeadTeacher(teacherId, id) {
  const url = "/gm_student/bind/head";
  return await httpGet(url, { teacherId, id }).then(handleResult);
}
// //逻辑删除 flag 1物理删除，!1逻辑删除
// export async function remove(id, flag) {
//   const url = "/gm_student/delete";
//   return await httpGet(url, { id, flag }).then(handleResult);
// }
